import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Text } from "@tarojs/components-rn";
import { toJS } from 'mobx';
import { inject, observer } from "@tarojs/mobx-rn";
import { pageSize, subtime } from "../../utils/common";
import buy_logStyleSheet from "./buy_log_styles";
var _styleSheet = buy_logStyleSheet;
let Company = class Company extends Component {
  constructor(porps) {
    super(porps);
    this.state = {
      totalCount: 0,
      items: [],
      pageIndex: 1,
      pageSize
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '购买记录' });
    this.getUserBuyAgencyLeval();
  }
  getUserBuyAgencyLeval() {
    let { userStore } = this.props.stores;
    let { pageIndex, pageSize } = this.state;
    userStore.getUserBuyAgencyLeval({
      pageIndex, pageSize,
      callback: res => {
        if (pageIndex === 1) {
          this.setState({ totalCount: toJS(res.totalCount), items: toJS(res.items) });
        } else {
          const { items } = this.state;
          items.push(...(res.items || []));
          this.setState({ totalCount: res.totalCount, items });
        }
      }
    });
  }
  onReachBottom() {
    let { totalCount, pageSize, pageIndex } = this.state;
    const { loading } = this.props.stores.homeStore;
    if (totalCount > pageIndex * pageSize && !loading) {
      this.setState({
        pageIndex: pageIndex + 1
      }, () => {
        this.getUserBuyAgencyLeval();
      });
    }
  }
  render() {
    let { items } = this.state;
    return <View style={_styleSheet["my-my_integral"]}>
        {items.length > 0 && items.map(item => {
        return <View key={item.agencyAmount} style={_styleSheet["list-19-item"]}>
                <View style={_styleSheet["l"]}>
                  <View style={_styleSheet["list-title"]}>建务通{item.agencyLevelView}(1年)</View>
                  <View style={_styleSheet["list-info"]}>{subtime(item.payTime)}</View>
                </View>
                <View style={_styleSheet["r"]}>
                  <Text style={_styleSheet["money"]}>-{item.agencyAmount}元</Text>
                </View>
              </View>;
      })}
        {items.length <= 0 && <View style={_styleSheet["page-none-info"]}>您还没有相关购买记录~</View>}
      </View>;
  }
};
Company = tslib_1.__decorate([inject("stores"), observer], Company);
export default Company;